home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_06 / letters / convert.c < prev    next >
Text File  |  1995-04-17  |  940b  |  36 lines

  1. /*
  2. ** Use a C programming trick here to increase
  3. ** performance. By casting the value as a
  4. ** character pointer and then subscripting, we
  5. ** can access the individual bytes in an long
  6. ** or short integer.
  7. */
  8. #define ByteNo(x,y) \
  9.         (((char *) (x))[(y)])
  10.  
  11. void swap_long_bytes( long *theLong )
  12. {
  13.         register char tempChar;
  14.         
  15.         /* swap bytes 0 and 3 */
  16.         tempChar = ByteNo(theLong,0);
  17.         ByteNo(theLong,0) = ByteNo(theLong,3);
  18.         ByteNo(theLong,3) = tempChar;
  19.         
  20.         /* swap bytes 1 and 2 */
  21.         tempChar = ByteNo(theLong,1);
  22.         ByteNo(theLong,1) = ByteNo(theLong,2);
  23.         ByteNo(theLong,2) = tempChar;
  24. }
  25.  
  26. void swap_short_bytes( short *theShort )
  27. {
  28.         register char tempChar;
  29.  
  30.         /* swap bytes 0 and 1 */
  31.         tempChar = ByteNo(theShort,0);
  32.         ByteNo(theShort,0) = ByteNo(theShort,1);
  33.         ByteNo(theShort,1) = tempChar;
  34. }
  35.  
  36.